<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	session.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="${basePath }">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="description" content="">
<meta name="author" content="">
<title>西普茗茶商品-确认订单</title>
<meta name="renderer" content="webkit">

<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="https://cdn.bootcss.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="assets/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
<link href="assets/css/animate.css" rel="stylesheet" type="text/css" />
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL STYLES -->
<link href="https://cdn.bootcss.com/Swiper/3.0.8/css/swiper.min.css" rel="stylesheet" type="text/css" />
<!-- END PAGE LEVEL STYLES -->
<!-- BEGIN THEME STYLES -->
<link href="assets/css/style-metronic.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style-responsive.css" rel="stylesheet" type="text/css" />
<link href="assets/css/plugins.css" rel="stylesheet" type="text/css" />
<link href="assets/css/themes/light.css" rel="stylesheet" type="text/css" id="style_color" />
<link href="assets/css/print.css" rel="stylesheet" type="text/css" media="print" />
<link href="assets/css/custom.css" rel="stylesheet" type="text/css" />
<link href="assets/css/pages/blog.css" rel="stylesheet" type="text/css" />
<link href="css/iconfont.css" rel="stylesheet" type="text/css" />
<!-- END THEME STYLES -->
<link rel="shortcut icon" href="favicon.ico" />

<script type="text/javascript">
	var isHTML5 = true;
</script>
<!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
	<script src="js/excanvas.min.js"></script> 
    <script type="text/javascript">
		isHTML5 = false;
	</script>
<![endif]-->

<style type="text/css">
body {
	background: #fef9f3 !important;
}
</style>
</head>
<!--/head-->
<!-- BEGIN BODY -->
<body class="page-footer-fixed">
	<!-- BEGIN HEADER -->
	<div class="header navbar">
		<div class="container-fluid">
			<div class="row">
				<div class="col-xs-2 text-center">
					<a href="./" class="icon_a_link">
						<i style="font-size: 24px; line-height: 40px; height: 40px;" class="iconfont icon-qh-home text-gold">&#xe61a;</i>
					</a>
				</div>
				<div class="col-xs-8 text-center">
					<h4>确认订单</h4>
				</div>
				<div class="col-xs-2 text-center">
					<a href="item/infocenter.jsp" class="icon_a_link">
						<i style="font-size: 24px; line-height: 40px; height: 40px;" class="iconfont text-gold icon-qh-infocenter">&#xe61d;</i>
					</a>
				</div>
			</div>
		</div>
	</div>
	<!-- END HEADER -->
	<div class="clearfix "></div>
	<!-- BEGIN CONTAINER -->
	<div class="page-container">

		<!-- BEGIN CONTENT -->
		<div class="page-content-wrapper">
			<div class="page-content no-space" style="margin-bottom: 50px !important; border-bottom: none !important;">

				<input type="hidden" id="goodsIds_input" value="${commonStr }">
				<input type="hidden" id="addressId_input" value="${buyerAddress.buyerAddressId }">
				<input type="hidden" id="coupon_input">

				<c:if test="${cartMap==null||fn:length(cartMap)<=0 }">
					<h4 class="text-center G-MarginTop50">
						<span class="glyphicon glyphicon-hand-right"></span> 您还没有选择商品吧！
					</h4>
				</c:if>
				<c:if test="${cartMap!=null&&fn:length(cartMap)>0 }">
					<!-- 清除浮动 -->
					<div class="clearfix"></div>
					<c:if test="${message!=null&&message!='' }">
						<div class="alert alert-warning margin-top-10" role="alert">${message }</div>
					</c:if>
					<c:if test="${canSubmitOrder==false }">
						<div class="alert alert-warning margin-top-10" role="alert">
							请返回
							<a href="cart">购物车</a>
							修改数量，或进入店铺购物凑够起送价或数量。
						</div>
					</c:if>
					<c:if test="${canSubmitOrder==true }">
						<div class="container margin-top-10 padding-top-10 padding-bottom-10 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
							<div class="row" id="select_address_button" href="get_buyer_ajax_address_list" data-target="#address_list_modal">
								<div class="col-xs-3 text-center">
									<h4 class="margin-top-10">
										<i style="font-size: 22px;" class="iconfont icon-qh-car text-gold">&#xe643;</i> 送至
									</h4>
								</div>
								<div class="col-xs-9 text-left">
									<i class="fa fa-angle-right pull-right margin-top-10 text-gold" style="font-size: 40px;"></i>
									<div id="show_address_detail_div">
										<c:if test="${buyerAddress!=null }">
											<span>${buyerAddress.buyerAddressDetail }</span>
											<br>
											<span>${buyerAddress.buyerAddressName }</span>
											<span>${buyerAddress.buyerAddressPhone }</span>
										</c:if>
										<c:if test="${buyerAddress==null }">
											<h4 class="margin-top-10">选择你的收货地址</h4>
										</c:if>
									</div>
								</div>
							</div>
						</div>
					</c:if>
					<div class="container margin-top-10 padding-top-10 padding-bottom-10 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
						<div class="blog-page no-space">
							<c:forEach items="${cartMap}" var="shoppingCarMap">
								<c:set var="operationMode" value="${shoppingCarMap.value.operationMode}"></c:set>
								<c:set var="goodsItemList" value="${shoppingCarMap.value.goodsItemList}"></c:set>
								<div class="container" style="background: #f5f5f5;">
									<div class="row">
										<div class="col-xs-12">
											<c:if test="${operationMode=='西普茗茶' }">
												<h4>${operationMode }
													<%-- <small><span class="label label-sm label-default">满${shopApplication.mzcMinNumber }件包邮</span></small> --%>
												</h4>
											</c:if>
											<c:if test="${operationMode=='西普茗茶' }">
												<h4>${operationMode }
													<%-- <small><span class="label label-sm label-default">满${shopApplication.qianhuiMinLimit }元包邮</span></small> --%>
												</h4>
											</c:if>
										</div>
									</div>
								</div>
								<div id="one_shop_div_${operationMode }" class="margin-top-5">
									<c:forEach items="${goodsItemList}" var="item" varStatus="itemStat">
										<div class="container">
											<div class="row">
												<div class="col-xs-12">
													<div class="media padding-top-5">
														<a href="item/${item.goods.goodsId }" class="pull-left">
															<img alt="" src="${item.goods.goodsMainPic }" class="media-object">
														</a>
														<div class="media-body">
															<h5 class="media-heading">
																<span>${item.goods.goodsName}</span>
															</h5>
															<p class="margin-top-10">
																<span class="text-light">价格：</span><span class="text-red"><strong><i class="fa fa-rmb"></i> <fmt:formatNumber value="${item.goods.goodsPrice}" type="currency" pattern="#,##0.##" /></strong></span>
															</p>
															<p>
																<span class="text-light">数量：</span><span class="text-red"><strong>${item.number }</strong></span>
															</p>
															<div class="clearfix"></div>
														</div>
													</div>
												</div>
											</div>
										</div>
										<div class="clearfix"></div>
									</c:forEach>
								</div>
							</c:forEach>
						</div>
					</div>
					<div class="clearfix"></div>
					<c:if test="${canSubmitOrder==true }">
						<div class="container margin-top-10 padding-top-10 padding-bottom-10 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
							<h5>
								<i style="font-size: 22px;" class="iconfont icon-qh-address text-gold">&#xe63e;</i> 配送方式：<span class="text-gold">西普茗茶商品配送</span>
							</h5>
							<hr>
							<div class="form-group">
								<label for="orderSendWay">派送时间 <span class="text-light"> (选择您方便的收货时间) </span></label> <select class="form-control" id="orderSendWay">
									<option value="工作日与节假日均可派送" selected="selected">工作日与节假日均可派送</option>
									<option value="工作日派送">工作日派送</option>
									<option value="节假日派送">节假日派送</option>
								</select>
							</div>
							<div class="form-group">
								<label for="buyerPeopleId">身份证号 <span class="text-light"> (填写本人真实身份证号，方便发货) </span></label>
								<input type="text" class="form-control" id="buyerPeopleId" placeholder="填写真实身份证号" value="${buyerSession.buyerPeopleId }">
							</div>
							<div class="form-group">
								<label for="exampleInputEmail1">姓名 <span class="text-light"> (填写本人真实姓名，方便发货) </span></label>
								<input type="text" class="form-control" id="buyerRealName" placeholder="填写真实姓名" value="${buyerSession.buyerRealName }">
							</div>
						</div>
						<c:if test="${buyerCouponViewList!=null&&fn:length(buyerCouponViewList)>0 }">
							<div class="container margin-top-10 padding-top-10 padding-bottom-10 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
								<div class="row">
									<div class="col-xs-12 text-left" id="select_coupon_button">
										<i class="fa fa-angle-right text-gold pull-right margin-top-10" style="font-size: 40px;"></i>
										<h4 class="margin-top-10" id="select_coupon_button_h4">
											<i style="font-size: 22px;" class="iconfont icon-qh-coupon text-gold">&#xe646;</i> 有优惠券可以使用
										</h4>
									</div>
								</div>
							</div>
						</c:if>

						<c:if test="${buyerSession.buyerPoints>0 }">
							<div class="container margin-top-10 padding-top-20 padding-bottom-20 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
								<span class="">你有${buyerSession.buyerPoints}积分，可以抵</span> <span class="text-red"><strong><i class="fa fa-rmb"></i> <fmt:formatNumber value="${buyerSession.buyerPoints*0.01}" type="currency"
											pattern="#,##0.##" /></strong></span> <span class="pull-right"><input id="usePoints" type="checkbox"></span>
							</div>
						</c:if>
						<div class="container margin-top-10 padding-top-10 padding-bottom-10 bg-white" style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;">
							<h4 class="text-center">
								<span class="text-black">总价：</span><span class="text-red"><strong><i class="fa fa-rmb"></i> <span id="all_total_price_span"><fmt:formatNumber value="${allTotalPrice}" type="currency"
												pattern="#,##0.##" /></span></strong></span>
							</h4>
							<!-- <h6 class="text-center">（不包含邮费和税）</h6> -->
							<br>
							<div>
								<button id="submit_order_button" class="btn btn-lg gold btn-block border-radius-5">提交订单</button>
							</div>
						</div>
					</c:if>
				</c:if>
			</div>
			<!-- END CONTAINER -->
		</div>
	</div>

	<c:if test="${buyerCouponViewList!=null&&fn:length(buyerCouponViewList)>0 }">
		<!-- 选择优惠券开始 -->
		<!-- /.modal -->
		<div class="modal fade" id="full" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog modal-full" style="margin-left: 0px !important; margin-right: 0px !important;">
				<div class="modal-content">
					<div class="modal-header">
						<h4 class="modal-title text-center">选择优惠券(最近20张)</h4>
					</div>
					<div class="modal-body">
						<c:forEach items="${buyerCouponViewList }" var="bc" varStatus="bcStat">
							<div class="row margin-top-10">
								<div class="col-xs-2 padding-top-10">
									<input type="radio" name="coupon_radio" class="coupon_radio_input" id="coupon_radio_${bc.buyerCoupon.buyerCouponId }" data-id="${bc.buyerCoupon.buyerCouponId }" data-text="${bc.coupon.couponName }">
								</div>
								<div class="col-xs-10">
									<button type="button" class="btn default btn-lg btn-block coupon_name_button" data-target="#coupon_radio_${bc.buyerCoupon.buyerCouponId }">${bc.coupon.couponName }
										<c:choose>
											<c:when test="${bc.coupon.couponType=='满减' }">(满<fmt:formatNumber type="number" value="${bc.coupon.param1 }" maxFractionDigits="0" />可用)
																</c:when>
											<c:when test="${bc.coupon.couponType=='立减' }">
											</c:when>
										</c:choose>
									</button>
								</div>
							</div>
						</c:forEach>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn default pull-left" data-dismiss="modal">关闭</button>
						<button type="button" class="btn blue pull-right" id="select_confirm_button">选择</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<!-- 选择优惠券结束 -->
	</c:if>

	<!-- 选择收货地址开始 -->
	<!-- /.modal -->
	<div class="modal fade" id="address_list_modal" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-full" style="margin-left: 0px !important; margin-right: 0px !important;">
			<div class="modal-content"></div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- 选择收货地址结束 -->
	<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
	<!-- BEGIN CORE PLUGINS -->
	<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
	<script src="https://cdn.bootcss.com/jquery-migrate/1.2.1/jquery-migrate.min.js" type="text/javascript"></script>
	<!-- IMPORTANT! Load jquery-ui-1.10.3.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
	<script src="assets/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="assets/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery.blockui.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery.cokie.min.js" type="text/javascript"></script>
	<script src="assets/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
	<script src="js/wow.min.js"></script>
	<script src="js/bootstrap.file-input.js"></script>
	<!-- END CORE PLUGINS -->
	<!-- BEGIN PAGE LEVEL PLUGINS -->
	<script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.0.8/js/swiper.jquery.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-validation/localization/messages_zh.js"></script>
	<script type="text/javascript" src="assets/plugins/select2/select2.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-bootpag/jquery.bootpag.min.js"></script>
	<script type="text/javascript" src="js/jquery.form.js"></script>
	<!-- END PAGE LEVEL PLUGINS -->
	<!-- BEGIN PAGE LEVEL SCRIPTS -->
	<script src="js/app.js"></script>
	<script src="js/AreaData_min.js"></script>
	<!-- END PAGE LEVEL SCRIPTS -->

	<script>
		$(function()
		{
			// Initiat WOW JS
			if (isHTML5 == true)
			{
				new WOW().init();
			}
			App.init();

			$("#select_address_button").click(function()
			{
				$("#address_list_modal").find(".modal-content").load($("#select_address_button").attr("href") + "?t=" + new Date().getTime());
				$('#address_list_modal').modal('show');
			});

			//提交订单
			$("#submit_order_button").click(function()
			{
				if ($("#addressId_input").val().length <= 0)
				{
					alert("请先选择收货地址");
					return false;
				}
				if ($("#orderSendWay").val().length <= 0)
				{
					alert("请选择配送时间方便您收货");
					return false;
				}
				if ($("#buyerPeopleId").val().length <= 0 || $("#buyerRealName").val().length <= 0)
				{
					alert("请填写身份证号和姓名方便发货");
					return false;
				}
				var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
				if (regIdCard.test($("#buyerPeopleId").val()) == false)
				{
					alert("身份证号填写有误，请检查一下。");
					return false;
				}

				var usePoints = $("#usePoints").is(':checked') ? true : false;

				//alert("你点击了提交订单按钮");
				$.post('${basePath}u_confirm_order_do',
				{
					'buyerAddress.buyerAddressId' : $("#addressId_input").val(),
					'commonStr' : $("#goodsIds_input").val(),
					'buyerPeopleId' : $("#buyerPeopleId").val(),
					'orderSendWay' : $("#orderSendWay").val(),
					'buyerRealName' : $("#buyerRealName").val(),
					'buyer_coupon_id' : $("#coupon_input").val(),
					'usePoints' : usePoints
				},
				//回调函数 
				function(json)
				{
					if (json.success == true)
					{
						//true, 则以 GET 方式，从服务端取最新的页面, 相当于客户端点击 F5("刷新")
						window.location.href = "${basePath}pay?ids=" + json.ids + "&showwxpaytitle=1";
					}
					else
					{
						alert(json.info);
					}
				},
				//返回类型
				"json");
			});

			//选择优惠券验证
			if ($("#select_coupon_button").length > 0)
			{
				$(".coupon_name_button").each(function()
				{
					var obj = $(this);
					obj.click(function()
					{
						$(obj.attr("data-target")).trigger("click");
						$.uniform.update();
					});
				});
				//弹出选择优惠券对话框
				$("#select_coupon_button").click(function()
				{
					$("#full").modal('show');
				});
				//选择优惠券
				$("#select_confirm_button").click(function()
				{
					if ($('input[name="coupon_radio"]:checked').length <= 0)
					{
						alert("请先选择优惠券");
						return false;
					}

					$.post('${basePath}u_valid_coupon_for_order_do',
					{
						'buyerAddress.buyerAddressId' : $("#addressId_input").val(),
						'commonStr' : $("#goodsIds_input").val(),
						'buyerPeopleId' : $("#buyerPeopleId").val(),
						'buyerRealName' : $("#buyerRealName").val(),
						'buyer_coupon_id' : $(".coupon_radio_input:checked").attr("data-id")
					},
					//回调函数 
					function(json)
					{
						if (json.success == true)
						{
							$("#select_coupon_button_h4").html('已选择"' + $(".coupon_radio_input:checked").attr("data-text") + '"');
							$("#full").modal('hide');
							if (json.tips != null)
							{
								alert(json.tips);
							}
							if (json.allTotalPrice != null)
							{
								$("#all_total_price_span").html(json.allTotalPrice);
							}
							$("#coupon_input").val($(".coupon_radio_input:checked").attr("data-id"));
						}
						else
						{
							alert(json.info);
						}
					},
					//返回类型
					"json");

				});
			}

		});
	</script>
	<!-- END JAVASCRIPTS -->
</body>
</html>